home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 1994 August / August CD.bin / Shareware / Education / numericalmethods Folder / chap_11 / a11_3b.m < prev    next >
Encoding:
Text File  |  1994-06-05  |  2.7 KB  |  100 lines  |  [MATS/MATL]

  1. echo off;
  2. % NUMERICAL METHODS: MATLAB Programs, (c) John H. Mathews 1994
  3. % To accompany the text:
  4. % NUMERICAL METHODS for Mathematics, Science and Engineering, 2nd Ed, 1992
  5. % Prentice Hall, Englewood Cliffs, New Jersey, 07632, U.S.A.
  6. % This free software is complements of the author.
  7.  
  8. % Algorithm 11.3 (Jacobi Iteration for Eigenvalues and Eigenvectors).
  9. % Section    11.3,    Jacobi's Method, Page 571
  10. echo on; clc; format long; hold off; clear
  11.  
  12. % JACOBI METHOD FOR FINDING EIGEN-PAIRS
  13.  
  14. % Assume that A is an n by n symmetric real matrix, thus
  15.  
  16. % it has a full set of eigenvectors  V , V  ,..., V .
  17. %                                     1   2        n
  18.  
  19. % The cyclic Jacobi`s method of iteration is used
  20.  
  21. % to find all of the eigen-pairs.
  22.  
  23. % Remark. jacobi2.m is used for Algorithm 11.3b
  24.  
  25. pause % Press any key to continue.
  26.  
  27. clc;
  28. %             JACOBI`S  METHOD FOR EIGENVECTORS
  29.  
  30. %      Assume that A is an n by n real symmetric matrix.
  31. % Then A has a full set of eigenvectors:
  32.  
  33. % V , V ,..., V .  Jacobi`s method of iteration is used
  34. %  1   2       n
  35.  
  36. % to find all the eigenvalues and eigenvectors of A. Let
  37.  
  38. % A = A , and construct a sequence of orthogonal
  39. %      1
  40. %                                    T
  41. % matrices { R  }  such that  D  =  R  A  R .
  42. %             j                j     j  j  j
  43.  
  44. % { D  } converges to the diagonal matrix D ,
  45. %    j
  46.  
  47. % of eigenvalues, and the sequence {V  = R R ...R }
  48. %                                    j    1 2    j
  49.  
  50. % converges to the matrix of eigenvectors.
  51.  
  52. pause % Press any key to continue.
  53.  
  54. clc;
  55. %      We use the cyclic Jacobi strategy for selecting the off
  56. % diagonal element to annihilate in the construction process.
  57. % Sweep through the matrix and annihilate elements in the
  58. % strict order
  59.  
  60. % a  ,a  ,...,a  ; a  ,a  ,...,a  ; ...;a
  61. %  12  13      1n   23  24      2n       n-1,n
  62.  
  63. %      For each sweep throughout the matrix, the computed
  64. % value t is the [R.M.S.] average of the diagonal elements
  65. % of A.  The user must supply the error tolerance for
  66. % annihilating the off diagonal elements
  67.  
  68. %        |d   |  >  t*epsilon       for all  q > p.
  69. %          p,q
  70.  
  71. pause % Press any key to continue.
  72.  
  73. clc;
  74. % Place the matrix in  A
  75.  
  76. % Place the tolerance in   epsilon
  77.  
  78. % Place the maximum cycles in  max1
  79.  
  80. A = [ 8   -1    3   -1;
  81.      -1    6    2    0;
  82.       3    2    9    1;
  83.      -1    0    1    7];
  84.  
  85. epsilon = 1e-16;
  86.  
  87. [V,D] = jacobi2(A,epsilon,1);
  88.  
  89. pause % Press any key to continue.
  90.  
  91. clc;
  92. Mx1 = 'Implementation of the cyclic Jacobi method.';
  93. Mx2 = 'The matrix  A  is:';
  94. Mx3 = 'The eigenvalues of  A  are:';
  95. Mx4 = 'The eigenvectors of  A  are:';
  96. clc,echo off,diary output,..
  97. disp(''),disp(Mx1),disp(''),disp(Mx2),disp(A),
  98. disp(Mx3),disp(diag(D)),disp(Mx4),disp(V),...
  99. diary off,echo on
  100.